package cn.cvs.mybatisplusvue.controller;

import cn.cvs.mybatisplusvue.entity.Student;
import cn.cvs.mybatisplusvue.service.StudentService;
import cn.cvs.mybatisplusvue.vo.ResultVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.processing.SupportedAnnotationTypes;

@RestController
@RequestMapping("/student")
public class studentController {
    @Autowired
    StudentService studentService;

    //分页带条件查询
    @GetMapping
    public ResultVo  getPage(String stuName,@RequestParam(defaultValue = "1") Integer pageNum){
        Page<Student> page=studentService.getPage(stuName,pageNum);
        return ResultVo.success("",page);
    }

    @PostMapping
    public ResultVo saveOrUpdate(@RequestBody Student student){
        studentService.saveOrUpdate(student);
        return ResultVo.success("操作成功",null);
    }

    @DeleteMapping("/{id}")
    public ResultVo del(@PathVariable Integer id){
        studentService.removeById(id);
        return ResultVo.success("删除成功",null);
    }
}
